package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.WorkflowProduct;
import com.qidianit.mes.pro.service.WorkflowProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/workflowProduct")
public class WorkflowProductController {

    @Autowired
    private WorkflowProductService workflowProductService;

    /* ---------- 接口13 ---------- */
    @GetMapping("/page")
    public Result<PageInfo<WorkflowProduct>> page(
            @RequestParam Long workflowId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return workflowProductService.selectPage(workflowId, page, size);
    }

    /* ---------- 接口14 ---------- */
    @PostMapping("/add")
    public Result<String> add(@RequestBody WorkflowProduct wp) {
        return workflowProductService.add(wp);
    }

    /* ---------- 接口15 ---------- */
    @GetMapping("/{id}")
    public Result<WorkflowProduct> selectById(@PathVariable Long id) {
        return workflowProductService.selectById(id);
    }

    /* ---------- 接口16 ---------- */
    @PutMapping("/update")
    public Result<WorkflowProduct> updateProduct(@RequestBody WorkflowProduct wp) {
        return workflowProductService.updateProduct(wp);
    }

    /* ---------- 接口17 ---------- */
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteProduct(@PathVariable Long id) {
        return workflowProductService.deleteProduct(id);
    }

    /* ---------- 接口18 ---------- */
    @DeleteMapping("/batchDelete")
    public Result<String> batchDelete(@RequestParam("id") List<Long> ids) {
        return workflowProductService.batchDelete(ids.toArray(new Long[0]));
    }
}